package com.yan.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yan.commonutils.R;
import com.yan.edu.entity.Course;
import com.yan.edu.entity.Teacher;
import com.yan.edu.service.CourseService;
import com.yan.edu.service.TeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/edu/indexfront")
@CrossOrigin
public class IndexFrontController {
@Autowired
private CourseService courseService;
@Autowired
private TeacherService teacherService;

//    查询前八个热门课程，和前四个热门讲师
@ApiOperation(value = "查询前八个热门课程，和前四个热门讲师")
@GetMapping("index")
public R index() {
    //查询前8条热门课程
    QueryWrapper<Course> wrapper = new QueryWrapper<>();
    wrapper.orderByDesc("id");
    wrapper.last("limit 8");
    List<Course> eduList = courseService.list(wrapper);

    //查询前4条名师
    QueryWrapper<Teacher> wrapperTeacher = new QueryWrapper<>();
    wrapperTeacher.orderByDesc("id");
    wrapperTeacher.last("limit 4");
    List<Teacher> teacherList = teacherService.list(wrapperTeacher);

    return R.ok().data("eduList",eduList).data("teacherList",teacherList);
}

}
